package bairui.international.weixin.portal.miniapp.controller.ticket.offset;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.querydsl.QSort;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;
import com.querydsl.core.BooleanBuilder;

import bairui.international.model.domain.jpa.TB_ElectronicTicket;
import bairui.international.model.domain.jpa.TB_User;
import bairui.international.model.status.State_ElectronicTicket;
import bairui.international.service.Service_ElectronicTicket;
import bairui.international.service.Service_User;

/**
 *
 * 列表
 *
 * @generated
 * 
 * @see STest_C_Ticket_Offset_Page_Get 测试
 *
 */
@Controller
public class C_Ticket_Offset_Page_Get
 extends SC_Ticket_Offset_Page_Get 
{
	
	@Autowired private Service_ElectronicTicket service_ElectronicTicket;
	@Autowired private Service_User service_User;
	
	/**
	 * Get请求
	 */
	@Action(Get.class)
	@GetMapping(Get.RequestMappingValue)
	public @FomatOutput @ResponseBody Object get(
		@RequestParam Integer startPage,
		@RequestParam String skey
	) throws Exception {
		TB_User user = service_User.findOne(it->it.skey.eq(skey));
		Page<TB_ElectronicTicket> page = service_ElectronicTicket.page(it->
					new BooleanBuilder()
					.or(it.assignedUser.eq(user).and(it.state.eq(State_ElectronicTicket.Assigned)))
					.or(it.takor.eq(user).and(it.state.eq(State_ElectronicTicket.Taked))
				),
					PageRequest.of(startPage, 8),
					it->new QSort(it.modifyTime.desc())
				);
		return page.map(it->new Output(it, skey));
	}

}
